package com.xian.daoimpl;

import java.util.List;

import javax.rmi.CORBA.Tie;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xian.dao.CategoryDao;
import com.xian.domain.Category;
import com.xian.domain.Greens;
import com.xian.domain.Order;

public class CategoryDaoImpl extends HibernateDaoSupport implements CategoryDao {

	@Override
	public void addupCategory(Category category) {
		this.getHibernateTemplate().save(category);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Greens> findCategoryPage(int pages) {
		Object[] objects ={(pages-1)*Greens.PANGESIZE,Greens.PANGESIZE};
		return getHibernateTemplate().find("from Category ");
	}

	@Override
	public int findCategorycount() {
		int n = 0;
		Query query = this.getSession().createQuery("select count(*) from Category");
		 n = new Integer(((Long) query.uniqueResult()).toString());
		return n;
	}

	@Override
	public List<Category> findCategorySort(String hql) {
		
		return getHibernateTemplate().find(hql);
	}

	@Override
	public void updateCategory(Category category) {
		
		this.getHibernateTemplate().update(category);
		
	}

	@Override
	public void deleteCategory(Category category) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(category);
	}

	
}
